

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagement.Mine;
using GameStateManagement.GameHelper;
#endregion

namespace GameStateManagement
{
    public class CommandEntry
    {
        #region Fields
        protected string text;
        protected float selectionFade;

        protected Vector2 position;
        #endregion

        #region Properties

        public bool TransitionEnabled { get; set; }

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        #endregion

        #region Events

        public event EventHandler<MyEventArgs> Selected;
        public event EventHandler<MyEventArgs> Ready;


        public virtual void OnSelectEntry(PlayerIndex playerIndex)
        {
            if (Selected != null)
                Selected(this, new MyEventArgs(playerIndex));
        }

        public virtual void OnReady()
        {
            if (Ready != null)
                Ready(this, null);

            
        }
        #endregion

        #region Initialization


        public CommandEntry(string text)
        {
            TransitionEnabled = true;
            this.text = text;
            this.Ready += new EventHandler<MyEventArgs>(MenuEntry_Ready);
            this.Selected += new EventHandler<MyEventArgs>(MenuEntry_Selected);

            
        }

        void MenuEntry_Selected(object sender, MyEventArgs e)
        {
            if (GameSettings.Instance.SoundEnable)
              GlobalSound.SoundDown.Play();
        }

        void MenuEntry_Ready(object sender, MyEventArgs e)
        {
            if (GameSettings.Instance.SoundEnable)
               GlobalSound.SoundOver.Play();
        }

        #endregion

        #region Update and Draw
        


        public virtual void Update(GameScreen screen, bool isSelected, GameTime gameTime)
        {

            float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

            if (isSelected)
                selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
            else
                selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
        }





        public virtual void Draw(GameScreen screen, bool isSelected, GameTime gameTime)
        {
        }


        public virtual int GetHeight(GameScreen screen)
        {
            return screen.ScreenManager.Font.LineSpacing;
        }

        public virtual int GetWidth(GameScreen screen)
        {
            return (int)screen.ScreenManager.Font.MeasureString(Text).X;
        }


        public virtual void Load(GameScreen screen)
        {

        }

        #endregion

    }
}
